class RulePanel extends BasePanel {

    private btn_xueliu: eui.RadioButton;
    private btn_xuezhan: eui.RadioButton;

    private scroller: eui.Scroller;
    private group: eui.Group;
    private lab_description: eui.Label;

    private type: RuleType;

    public constructor() {
        super();

        this.skinName = "RulePanelSkin";
    }

    childrenCreated() {
        super.childrenCreated();

        this.type = RuleType.xueliuchenghe;

        this.update();

        this.btn_xueliu.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickHandler, this);
        this.btn_xuezhan.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickHandler, this);
    }

    private clickHandler(e: egret.TouchEvent) {
        switch (e.currentTarget) {
            case this.btn_xueliu:
                this.type = RuleType.xueliuchenghe;
                break;
            case this.btn_xuezhan:
                this.type = RuleType.xuezhandaodi;
                break;
        }

        this.update();
    }

    update(): void {

        if (!GameConfig.introduction) return;

        let json: any;

        switch (this.type) {
            case RuleType.xuezhandaodi:
                json = GameConfig.introduction['xuezhan'];
                break;
            case RuleType.xueliuchenghe:
                json = GameConfig.introduction['xueliu'];
                break;
        }

        if (!json) return;

        let desc: string = "";

        if (json.title && json.title != "") {
            desc += "　　" + json.title;
        }

        let rule: any;
        for (let key1 in json.content) {
            rule = json.content[key1];

            if (!rule) continue;

            desc += "\n\n　　" + rule["desc"];

            if (!rule.list) continue;

            for (let key2 in rule.list) {
                desc += "\n　　　" + rule.list[key2];
            }
        }

        this.lab_description.text = desc;

        this.scroller.viewport.scrollV = 0;
        this.scroller.validateNow();
    }
}